package com.wty.basic.objectReference;

import com.wty.basic.pojo.School;
import com.wty.basic.pojo.Student;

/**
 * 关于参数的引用
 */
public class Test3 {

    public static void main(String args[]){
        Student stu1=new Student("wty",18,new School("tust",2000));
        System.out.println("执行方法前");
        System.out.println(stu1.getName());
        System.out.println(stu1.getAge());
        System.out.println(stu1.getSchool().getName()+stu1.getSchool().getNum());
        test2(stu1);
        System.out.println("执行方法后");
        System.out.println(stu1.getName());
        System.out.println(stu1.getAge());
        System.out.println(stu1.getSchool().getName()+stu1.getSchool().getNum());


        System.out.println("----------------------------分割线-------------------------------------");
        char[] chars=new char[]{'a','b','c','d','e'};
        System.out.println("before update");
        System.out.println(chars);
        test3(chars);
        System.out.println("after update");
        System.out.println(chars);

    }


    /**
     * 引用作为参数 引用操作的仍然是引用指向的对象
     * @param stu
     */
    public static void test1(Student stu){
        stu.setName("test1");
        stu.setAge(10086);
        stu.setSchool(new School("test1",20000));
    }

    /**
     * 引用作为参数 如果指向了新的地址 不影响原来的对象
     * @param stu
     */
    public static void test2(Student stu){
        stu=new Student("test2",20,new School("test2",10000));
    }

    public static void test3(char[] chars){
        //引用作为参数 如果指向了新的地址 不影响原来的对象
        //chars=new char[]{'e','d','c','b','a'};
        //这不是修改了形参的指向，是直接修改了值
        chars[0]='g';
    }
}
